// app/frontend/eslint.config.mjs

import globals from "globals";
import tseslint from "typescript-eslint";
import vuePlugin from "eslint-plugin-vue";
import prettierConfig from "eslint-config-prettier";
import { FlatCompat } from "@eslint/eslintrc";
import vueParser from "vue-eslint-parser";
import { parser as tsParser } from "typescript-eslint";

export default [
  // 1. 全局忽略配置
  {
    ignores: [
      "dist/",
      "node_modules/",
      "public/",
      "*.d.ts", // 忽略所有 TypeScript 声明文件
      "*.mjs",
      "src/core/*",
      "src/layouts/*",
      "src/assets/ts/*",
      "src/views/crafted/*",
      "src/stores/*",
      "src/views/LayoutBuilder.vue",
      "src/components/highlighters/*",
      "src/components/menu/*",
      "src/services/base/*",
      "src/types/common/*",
      "src/services/business/auth.service.ts",
    ],
  },

  // 2. 全局语言和环境配置
  {
    languageOptions: {
      globals: {
        ...globals.browser, // 浏览器全局变量
        ...globals.node, // Node.js 全局变量
      },
    },
  },

  // 3. TypeScript 核心配置
  ...tseslint.configs.recommended,

  // TypeScript 文件特定配置
  {
    files: ["**/*.ts", "**/*.tsx"],
    languageOptions: {
      parser: tsParser,
    },
  },

  // Vue 文件特定配置
  {
    files: ["**/*.vue"],
    languageOptions: {
      parser: vueParser,
      parserOptions: {
        parser: {
          ts: tsParser,
        },
      },
    },
  },

  // 4. Vue 核心配置
  ...vuePlugin.configs["flat/recommended"],

  // 5. 自定义规则 (在这里覆盖或添加规则)
  {
    rules: {
      // --- TypeScript 规则 ---
      "@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }],
      "@typescript-eslint/explicit-module-boundary-types": "off",

      // --- Vue 规则 ---
      "vue/multi-word-component-names": "warn", // 建议使用多词组件名，但非强制错误
      "vue/max-attributes-per-line": [
        "error",
        {
          singleline: { max: 3 },
          multiline: { max: 1 },
        },
      ],
      "vue/html-self-closing": [
        "error",
        {
          html: {
            void: "always",
            normal: "always",
            component: "always",
          },
          svg: "always",
          math: "always",
        },
      ],
      "vue/component-name-in-template-casing": ["error", "PascalCase"],
    },
  },

  // 6. Prettier 集成配置 (必须放在最后！)
  // 这个配置会关闭所有与 Prettier 冲突的 ESLint 规则。
  prettierConfig,
];
